package patrol.mobile.com.mobilepatrol.adapter;

import android.graphics.Paint;
import android.view.View;
import android.widget.TextView;

import com.dl7.recycler.adapter.BaseQuickAdapter;
import com.dl7.recycler.adapter.BaseViewHolder;

import java.util.ArrayList;
import java.util.List;

import patrol.mobile.com.mobilepatrol.R;
import patrol.mobile.com.mobilepatrol.activity.track.TrackListActivity;
import patrol.mobile.com.mobilepatrol.bean.PatrolInfoBean;
import patrol.mobile.com.mobilepatrol.utils.DateUtil;

/**
 * Created by long on 2016/8/24.
 * 巡道列表
 */
public class TrackListAdapter extends BaseQuickAdapter<PatrolInfoBean> {
    private TrackListActivity context;
    private List<String> qlcodes = new ArrayList<>();
    public TrackListAdapter(TrackListActivity context, List<PatrolInfoBean> data) {
        super(context, data);
        this.context =  context;
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.item_track2;
    }

    @Override
    protected void convert(final BaseViewHolder holder, final PatrolInfoBean item) {
        holder.setText(R.id.index,item.index+"");
        holder.setText(R.id.tv1, item.roadLine+"( K"+item.startPotKm+"+"+item.startPotMeter+" - K"+item.endPotKm+"+"+item.endPotMeter+")");
//        holder.setText(R.id.tv2, "起始桩号："+item.startPotKm+"+"+item.startPotMeter);
        holder.setText(R.id.tv3, item.weather);
        holder.setText(R.id.tv4, DateUtil.StringPattern(item.roadDate,DateUtil.format1,DateUtil.format2));
        holder.setText(R.id.tv5, item.roader);
        holder.setText(R.id.tv6, item.patrolType);
        holder.setText(R.id.tv_go,item.detailInfoBeans.size()+"条");
        TextView tv_go = holder.getView(R.id.tv_go);
        tv_go.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); //下划线
        tv_go.getPaint().setAntiAlias(true);//抗锯齿
        holder.getView(R.id.tv_go).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                context.goDetail(item.ID);
            }
        });
        //0没有上传
        if (item.status==0){
            holder.setInVisible(R.id.iv_up,false);
            holder.setInVisible(R.id.iv_noup,true);
            holder.getView(R.id.iv_noup).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    context.upload(item.ID);
                }
            });
        }else{
            holder.setInVisible(R.id.iv_up,true);
            holder.setInVisible(R.id.iv_noup,false);

        }

    }
    public List<String> getQlcodes(){
        return qlcodes;
    }
}
